package com.wswy.wzcx.ui.module.tels

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentPagerAdapter
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.wswy.wzcx.R
import com.wswy.wzcx.module.base.CBaseFragment
import com.wswy.wzcx.utils.Tools
import kotlinx.android.synthetic.main.f_sos_numbers.*

/**
 * 应急电话
 */
class CommonNumbersFragment : CBaseFragment() {

    override fun getContentLayoutId(): Int {
        return R.layout.f_sos_numbers
    }

    override fun getFragmentTitle(): String {
        return "应急电话"
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        initView()

        val array = arrayOf("道路救援","保险公司")

        array.forEach {
            tabLayout.addTab(tabLayout.newTab().setText(it))
        }

        tabLayout.setupWithViewPager(vp_tels)

        vp_tels.adapter = object : FragmentPagerAdapter(childFragmentManager){
            override fun getItem(position: Int): Fragment {
                return TelListFragment.newInstance(position)
            }

            override fun getCount(): Int= array.size

            override fun getPageTitle(position: Int): CharSequence? {
                return array[position]
            }
        }


        indicator.setTabLayoutAndViewPager(tabLayout, vp_tels)
        tabLayout.requestLayout()
    }


    private fun initView(){

        val clickedListener = View.OnClickListener {

            ((it as? ViewGroup)?.getChildAt(1) as? TextView)?.text?.run {

                Tools.startCallPhone(it.context,this.toString())

            }

        }

        ll_num_1.setOnClickListener(clickedListener)
        ll_num_2.setOnClickListener(clickedListener)
        ll_num_3.setOnClickListener(clickedListener)
        ll_num_4.setOnClickListener(clickedListener)

    }


}